#include <iostream>
#include "UnidirectionLinkedList.hpp"
using namespace std;

// class Solution
//{
// public:
//     bool hasCycle(ListNode *head)
//     {
//         while (head!= nullptr)
//         {
//             if(head->val == 100001)
//                 return true;
//             head->val = 100001;
//             head = head->next;
//         }
//         return false;
//     }
// };

class Solution
{
public:
    bool hasCycle(ListNode *head)
    {
        auto fastPtr = head;
        auto slowPtr = head;
        while (fastPtr != nullptr && fastPtr->next != nullptr)
        {
            fastPtr = fastPtr->next->next;
            slowPtr = slowPtr->next;
            if (fastPtr == slowPtr)
                return true;
        }
        return false;
    }
};

int main()
{
    cout << "Code141" << endl;
    Solution s;
    return 0;
}